package m.jclecai.com.dialog;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Html;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import m.jclecai.com.R;
import m.jclecai.com.listener.OnSclestListener;
import m.jclecai.com.utils.BitmapUtil;
import m.jclecai.com.utils.ScreenUtil;
import m.jclecai.com.utils.http.FastOk;

/**
 * Created by ZD on 2017/5/4.
 * <p>
 * 精彩篮球的对话框
 */

public class JczqHHDialog extends BaseDialog {


    @BindView(R.id.llSFCContainer)
    LinearLayout llSFCContainer;
    @BindView(R.id.llSPFContainer)
    LinearLayout llSPFContainer;
    @BindView(R.id.llBFContainer)
    LinearLayout llBFContainer;
    @BindView(R.id.llZJQContainer)
    LinearLayout llZJQContainer;
    @BindView(R.id.llBQCContainer)
    LinearLayout llBQCContainer;
    @BindView(R.id.llSFCTContainer)
    LinearLayout llSFCTContainer;
    Context mContext;
    @BindView(R.id.ll_spf)
    RelativeLayout llSpf;
    @BindView(R.id.ll_rqspf)
    RelativeLayout llRQSpf;
    @BindView(R.id.ll_bf)
    RelativeLayout llBf;
    @BindView(R.id.ll_zjq)
    RelativeLayout llZjq;
    @BindView(R.id.ll_bqc)
    RelativeLayout llBqc;
    @BindView(R.id.ll_sfc)
    RelativeLayout llSfc;
    @BindView(R.id.tv_bqc)
    TextView tv_bqc;
    @BindView(R.id.tv_bf)
    TextView tv_bf;
    @BindView(R.id.homeTeamName)
    TextView homeTeamName;
    @BindView(R.id.awayTeamName)
    TextView awayTeamName;
    @BindView(R.id.tv_spf)
    TextView tv_spf;
    @BindView(R.id.tv_zjq)
    TextView tv_zjq;


    public enum JCZQSHOWTYPE {
        SHOWSPF, SHOWBF, SHOWZJQ, SHOWBQC, SHOWALL, SHOWDG, SHOWSFC
    }

    JCZQSHOWTYPE type = JCZQSHOWTYPE.SHOWALL;

    //red_white_selecter 的边线宽度
    int splitWidth = 0;

    String[] codes;
    List<String[]> list;
    Map<String, Map<String, String>> map;

    public JczqHHDialog(Context context, String[] codes, Map<String, Map<String, String>> map, JCZQSHOWTYPE type) {
        super(context);
        this.mContext = context;
        this.codes = codes;
        if (type.equals(JCZQSHOWTYPE.SHOWSFC))
            this.list = FastOk.getList(codes[15], String[].class);
        else
            this.list = FastOk.getList(codes[16], String[].class);
        this.map = map;
        this.type = type;
        if (this.map == null)
            this.map = new HashMap<>();
        initView();
    }

    private void initView() {
        setContentView(R.layout.dialog_jczq_hh);
        //左边队名-公共属性
        homeTeamName.setText(codes[3]);
        //右边队名-公共属性
        awayTeamName.setText(codes[4]);
        llSPFContainer.setVisibility(View.GONE);
        llBFContainer.setVisibility(View.GONE);
        llZJQContainer.setVisibility(View.GONE);
        llBQCContainer.setVisibility(View.GONE);
        llSFCTContainer.setVisibility(View.GONE);
        tv_bf.setVisibility(View.VISIBLE);
        tv_bqc.setVisibility(View.VISIBLE);
        if (list == null || (list != null && list.size() <= 0)) {
            return;
        }
        String[] cbf = mContext.getResources().getStringArray(
                R.array.jczq_cbf);
        String[] spf = mContext.getResources().getStringArray(
                R.array.jczq_spf);
        String[] bqc = mContext.getResources().getStringArray(
                R.array.jczq_bqc);
        splitWidth = ScreenUtil.dpToPx(mContext, 0.5f);
        int height = ScreenUtil.dpToPx(mContext, 40);
        int width = ScreenUtil.getScreenWidth(mContext) - ScreenUtil.dip2px(mContext, 40);
        int vWidth = 0;
        switch (type) {
            case SHOWSPF:
                llSPFContainer.setVisibility(View.VISIBLE);
                vWidth = width / 3;
                addSPF(spf, vWidth, height, 3, "0_spf_", llSpf, 0);
                addSPF(spf, vWidth, height, 3, "1_rqspf_", llRQSpf, 1);
                break;
            case SHOWBF:
                llBFContainer.setVisibility(View.VISIBLE);
                tv_bf.setVisibility(View.GONE);
                vWidth = width / 5;
                addBF(cbf, vWidth, height, 5);
                break;
            case SHOWZJQ:
                tv_zjq.setVisibility(View.GONE);
                llZJQContainer.setVisibility(View.VISIBLE);
                vWidth = width / 4;
                addZJQ(vWidth, height, 4);
                break;
            case SHOWBQC:
                llBQCContainer.setVisibility(View.VISIBLE);
                tv_bqc.setVisibility(View.GONE);
                vWidth = width / 3;
                addBQC(bqc, vWidth, height, 3);
                break;
            case SHOWDG:
                //这里的话，我们是需要判断一下，这种玩法是否有单关，比如让胜平负是没有单关的，比分，总进球之类的是永远有的单关；

                width = ScreenUtil.getScreenWidth(mContext) - ScreenUtil.dip2px(mContext, 60);
                llSPFContainer.setVisibility(View.VISIBLE);
                llBFContainer.setVisibility(View.VISIBLE);
                llZJQContainer.setVisibility(View.VISIBLE);
                llBQCContainer.setVisibility(View.VISIBLE);
                vWidth = width / 3;
                //在在这里我们要判断一下是否支持单关，如果支持了，我们才显示；
                if (isSupportDanguan("spf")) {
                    addSPF(spf, vWidth, height, 3, "0_spf_", llSpf, 0);        //胜负彩；
                } else {
                    TextView tvSpf = new TextView(mContext);
                    tvSpf.setText("未开售单关固赔率");
                    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    tvSpf.setLayoutParams(layoutParams);
                    tvSpf.setEnabled(false);
                    tvSpf.setGravity(Gravity.CENTER);
                    tvSpf.setTextSize(12);
                    tvSpf.setPadding(0, 10, 0, 10);
                    tvSpf.setBackground(mContext.getResources().getDrawable(R.drawable.red_white_selecter));
                    llSpf.addView(tvSpf);
                }


                if (isSupportDanguan("rqspf")) {
                    addSPF(spf, vWidth, height, 3, "1_rqspf_", llRQSpf, 1);     //胜负彩；
                } else {
                    TextView tvSpf = new TextView(mContext);
                    tvSpf.setText("未开售单关固赔率");
                    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                    tvSpf.setLayoutParams(layoutParams);
                    tvSpf.setEnabled(false);
                    tvSpf.setGravity(Gravity.CENTER);
                    tvSpf.setTextSize(12);
                    tvSpf.setPadding(0, 10, 0, 10);
                    tvSpf.setBackground(mContext.getResources().getDrawable(R.drawable.red_white_selecter));
                    llRQSpf.addView(tvSpf);
                }


                //让球胜负彩是没有单关的；
//                TextView textView = new TextView(mContext);
//                textView.setText("未开售单关固赔率");
//                RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
//                textView.setLayoutParams(layoutParams);
//                textView.setEnabled(false);
//                textView.setGravity(Gravity.CENTER);
//                textView.setTextSize(12);
//                textView.setPadding(0,10,0,10);
//                textView.setBackground(mContext.getResources().getDrawable(R.drawable.red_white_selecter));
//                llRQSpf.addView(textView);
                //addSPF(spf, vWidth, height, 3,"1_rqspf_",llRQSpf,1);    //让球胜负彩
                vWidth = width / 5;
                addBF(cbf, vWidth, height, 5);      //这里是比分
                vWidth = width / 4;
                addZJQ(vWidth, height, 4);
                vWidth = width / 3;
                addBQC(bqc, vWidth, height, 3);    //半球场

                break;
            case SHOWALL:
                width = ScreenUtil.getScreenWidth(mContext) - ScreenUtil.dip2px(mContext, 60);
                llSPFContainer.setVisibility(View.VISIBLE);
                llBFContainer.setVisibility(View.VISIBLE);
                llZJQContainer.setVisibility(View.VISIBLE);
                llBQCContainer.setVisibility(View.VISIBLE);
                vWidth = width / 3;
                addSPF(spf, vWidth, height, 3, "0_spf_", llSpf, 0);
                addSPF(spf, vWidth, height, 3, "1_rqspf_", llRQSpf, 1);
                vWidth = width / 5;
                addBF(cbf, vWidth, height, 5);
                vWidth = width / 4;
                addZJQ(vWidth, height, 4);
                vWidth = width / 3;
                addBQC(bqc, vWidth, height, 3);
                break;
            case SHOWSFC:
                //左边队名-公共属性
                homeTeamName.setText(codes[4]);
                //右边队名-公共属性
                awayTeamName.setText(codes[3]);
                String[] sfc = mContext.getResources().getStringArray(
                        R.array.jclq_sfc);
                String[] sfcValue = mContext.getResources().getStringArray(
                        R.array.jclq_sfc_value);
                llSFCTContainer.setVisibility(View.VISIBLE);
                llSFCContainer.setVisibility(View.VISIBLE);
                vWidth = width / 3;
                addSFC(sfc, sfcValue, vWidth, height, 3, "3_sfc_", llSfc, 7);
                break;
        }
    }


    void addSPF(String[] spf, int width, int height, int maxLine, String perfix, ViewGroup view, int dataIndex) {
        String tColor = Integer.parseInt(codes[5]) > 0 ? "#f03d3d" : "#14a514";
        tv_spf.setText(codes[5]);
        tv_spf.setBackgroundColor(BitmapUtil.getTextColor(tColor));
        int wm = 0;
        int hm = -splitWidth;
        //因为我从0的时候就+height 所有初始化的时候-height 就刚刚好是0
        int topMargin = -height;
        int leftMargin = ((maxLine - 1) * splitWidth) / 2;
        int index = 0;
        for (int i = 0; i < spf.length; i++) {
            leftMargin += width;
            wm += ScreenUtil.dpToPx(mContext, 0.5f);
            if (index % maxLine == 0) {
                wm = 0;
                //这里初始化 ((maxLine - 1) * splitWidth) / 2 是由于两个格子都有边框 所有并排在一起的地方会很粗
                //我就将后一个的位置的边线与前一个重叠 然后重叠出来的空间 分配给整个容器左右两边当间距
                leftMargin = ((maxLine - 1) * splitWidth) / 2;
                topMargin += height;
                hm += splitWidth;
            }
            StringBuilder str = new StringBuilder();
            boolean isNotSale = true;
            try {
                isNotSale = isNotSale(list.get(dataIndex)[i]);
            } catch (Exception e) {

            }
            if (isNotSale) {
                str.append("未开售");
            } else {
                if (spf[i].equals("3")) {
                    str.append("胜");
                } else if (spf[i].equals("1")) {
                    str.append("平");
                } else if (spf[i].equals("0")) {
//                str.append("主负");
                    str.append("负");
                }
            }
            StringBuilder tag = new StringBuilder();
            try {
                tag.append(perfix + (i) + "_" + list.get(dataIndex)[i]);
            } catch (Exception e) {

            }
            tag.append("_" + str.toString() + "_" + spf[i]);
            str.append("<br/><small><small>");
            try {
                str.append(list.get(dataIndex)[i]);
            } catch (Exception e) {

            }
            str.append("</small></small>");
            boolean isCheck = isCheckThisView(tag.toString(), String.valueOf(dataIndex));
//            int color = Color.parseColor(Integer.parseInt(codes[5]) > 0 ? "#f03d3d" : "#14a514");
            int color = BitmapUtil.getTextColor(codes[17]);
            String key = "(" + codes[5] + ")";
            view.addView(createCheckBox(width, height,
                    leftMargin > 0 ? leftMargin - wm : leftMargin,
                    topMargin > 0 ? topMargin - hm : topMargin,
                    str.toString(), tag.toString(), isCheck, color, key, !isNotSale));
            index++;
        }
    }

    void addBF(String[] bf, int width, int height, int maxLine) {
        //因为我从0的时候就+height 所有初始化的时候-height 就刚刚好是0
        int wm = 0;
        int hm = -splitWidth;
        int topMargin = -height;
        int leftMargin = ((maxLine - 1) * splitWidth) / 2;
        boolean br = false;
        int index = 0;
        for (int i = 0; i < bf.length; i++) {
            leftMargin += width;
            wm += ScreenUtil.dpToPx(mContext, 0.5f);
            if (br) {
                //补齐 从头开始排列
                br = false;
                index = 0;
            }
            if (index % maxLine == 0) {
                wm = 0;
                //这里初始化 ((maxLine - 1) * splitWidth) / 2 是由于两个格子都有边框 所有并排在一起的地方会很粗
                //我就将后一个的位置的边线与前一个重叠 然后重叠出来的空间 分配给整个容器左右两边当间距
                leftMargin = ((maxLine - 1) * splitWidth) / 2;
                topMargin += height;
                hm += splitWidth;
            }
            StringBuilder str = new StringBuilder();
            if (bf[i].equals("9:0")) {
                str.append("胜其它");
                br = true;
            } else if (bf[i].equals("9:9")) {
                str.append("平其它");
            } else if (bf[i].equals("0:9")) {
                str.append("负其它");
            } else {
                str.append(bf[i]);
            }
            StringBuilder tag = new StringBuilder();
            tag.append("3_cbf_" + i + "_" + list.get(3)[i]);
            tag.append("_" + str.toString() + "_" + bf[i]);
            str.append("<br/><small><small>");
            str.append(list.get(3)[i]);
            str.append("</small></small>");
            boolean isCheck = isCheckThisView(tag.toString(), "3");
            llBf.addView(createCheckBox(width, height, leftMargin > 0 ? leftMargin - wm : leftMargin,
                    topMargin > 0 ? topMargin - hm : topMargin, str.toString(),
                    tag.toString(), isCheck));
            index++;
        }
    }

    void addZJQ(int width, int height, int maxLine) {
        int wm = 0;
        int hm = -splitWidth;
        //因为我从0的时候就+height 所有初始化的时候-height 就刚刚好是0
        int topMargin = -height;
        int leftMargin = ((maxLine - 1) * splitWidth) / 2;
        int index = 0;
        for (int i = 0; i < list.get(2).length; i++) {
            leftMargin += width;
            wm += ScreenUtil.dpToPx(mContext, 0.5f);
            if (index % maxLine == 0) {
                wm = 0;
                //这里初始化 ((maxLine - 1) * splitWidth) / 2 是由于两个格子都有边框 所有并排在一起的地方会很粗
                //我就将后一个的位置的边线与前一个重叠 然后重叠出来的空间 分配给整个容器左右两边当间距
                leftMargin = ((maxLine - 1) * splitWidth) / 2;
                topMargin += height;
                hm += splitWidth;
            }
            StringBuilder str = new StringBuilder();
            if (i == list.get(2).length - 1) {
                str.append(i + "+球");
            } else {
                str.append(i + "球");
            }
            str.append("<br/><small><small>");
            str.append(list.get(2)[i]);
            str.append("</small></small>");
            StringBuilder tag = new StringBuilder();
            tag.append("2_jqs_" + i + "_" + list.get(2)[i] + "_" + i + "_" + i);
            boolean isCheck = isCheckThisView(tag.toString(), "2");
            llZjq.addView(createCheckBox(width, height, leftMargin > 0 ? leftMargin - wm : leftMargin,
                    topMargin > 0 ? topMargin - hm : topMargin,
                    str.toString(), tag.toString(), isCheck));
            index++;
        }
    }

    void addBQC(String[] bqc, int width, int height, int maxLine) {
        int wm = 0;
        int hm = -splitWidth;
        //因为我从0的时候就+height 所有初始化的时候-height 就刚刚好是0
        int topMargin = -height;
        int leftMargin = ((maxLine - 1) * splitWidth) / 2;
        int index = 0;
        for (int i = 0; i < bqc.length; i++) {
            leftMargin += width;
            wm += ScreenUtil.dpToPx(mContext, 0.5f);
            if (index % maxLine == 0) {
                wm = 0;
                //这里初始化 ((maxLine - 1) * splitWidth) / 2 是由于两个格子都有边框 所有并排在一起的地方会很粗
                //我就将后一个的位置的边线与前一个重叠 然后重叠出来的空间 分配给整个容器左右两边当间距
                leftMargin = ((maxLine - 1) * splitWidth) / 2;
                topMargin += height;
                hm += splitWidth;
            }
            StringBuilder str = new StringBuilder();
            str.append(bqc[i].replaceAll("0", "负").replaceAll("1", "平").replaceAll("3", "胜").replaceAll("-", ""));
            StringBuilder tag = new StringBuilder();
            tag.append("4_bqc_" + i + "_" + list.get(4)[i] + "_" + str.toString() + "_" + bqc[i]);
            str.append("<br/><small><small>");
            str.append(list.get(4)[i]);
            str.append("</small></small>");
            boolean isCheck = isCheckThisView(tag.toString(), "4");
            llBqc.addView(createCheckBox(width, height, leftMargin > 0 ? leftMargin - wm : leftMargin,
                    topMargin > 0 ? topMargin - hm : topMargin,
                    str.toString(), tag.toString(), isCheck));
            index++;
        }
    }

    void addSFC(String[] sfc, String[] sfcValue, int width, int height, int maxLine, String perfix, ViewGroup view, int dataIndex) {
        int wm = 0;
        int hm = -splitWidth;
        //因为我从0的时候就+height 所有初始化的时候-height 就刚刚好是0
        int topMargin = -height;
        int leftMargin = ((maxLine - 1) * splitWidth) / 2;
        int index = 0;
        for (int i = 0; i < sfc.length; i++) {
            leftMargin += width;
            wm += ScreenUtil.dpToPx(mContext, 0.5f);
            if (index % maxLine == 0) {
                wm = 0;
                //这里初始化 ((maxLine - 1) * splitWidth) / 2 是由于两个格子都有边框 所有并排在一起的地方会很粗
                //我就将后一个的位置的边线与前一个重叠 然后重叠出来的空间 分配给整个容器左右两边当间距
                leftMargin = ((maxLine - 1) * splitWidth) / 2;
                topMargin += height;
                hm += splitWidth;
            }

            //formatLQSFCText(game,sfc[i],);
            String game = i < 6 ? "客胜" : "主胜";

            if (null != list && list.size() > 0) {
                if (list.size() < dataIndex)
                    return;
                String[] Str = list.get(dataIndex);
                if (Str.length <= i)
                    return;
                //这里拼接tag
                StringBuilder tag = new StringBuilder();
                tag.append(perfix + (i) + "_" + list.get(dataIndex)[i]);
                tag.append("_" + game + sfc[i] + "_" + sfcValue[i].replaceAll("[+]", ""));

                //这里拼接显示部分
                String str = showLQSFCText(sfc[i], list.get(dataIndex)[i]);

                boolean isCheck = isCheckThisView(tag.toString(), "5");
                view.addView(createCheckBox(width, height, leftMargin > 0 ? leftMargin - wm : leftMargin,
                        topMargin > 0 ? topMargin - hm : topMargin,
                        str.toString(), tag.toString(), isCheck));
                index++;
            }
        }
    }

    /**
     * 返回比分和配置
     *
     * @param title
     * @param odd   return
     */
    public String showLQSFCText(String title, String odd) {

        StringBuilder str = new StringBuilder();
        str.append(title);
        str.append("<br/><small><small>");
        str.append(odd);
        str.append("</small></small>");
        return str.toString();
    }


    CheckBox createCheckBox(int width, int height, int leftMargin, int topMargin, String text, String tag, boolean isCheck) {
        return createCheckBox(width, height, leftMargin, topMargin, text, tag, isCheck, -1, "", true);
    }

    CheckBox createCheckBox(int width, int height, int leftMargin, int topMargin, String text, String tag, boolean isCheck, boolean isNotSale) {
        return createCheckBox(width, height, leftMargin, topMargin, text, tag, isCheck, -1, "", isNotSale);
    }

    /**
     * @param width      宽
     * @param height     高
     * @param leftMargin 左边距
     * @param topMargin  上边距
     * @param text       文本
     * @param tag        标记文本(携带下标-采种-倍数)
     * @param isCheck    是否选中
     * @param color      特殊文字变色
     * @param keyword    需要变色的特殊文字
     * @return
     */
    CheckBox createCheckBox(int width, int height, int leftMargin, int topMargin, String text, String tag, boolean isCheck, int color, String keyword, boolean isNotSale) {
        CheckBox cb = new CheckBox(mContext);
        RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(width, height);
        rl.leftMargin = leftMargin;
        rl.topMargin = topMargin;
        cb.setLayoutParams(rl);
        cb.setButtonDrawable(R.color.bh);
        cb.setTextColor(ContextCompat.getColorStateList(mContext, R.color.black_white_selector));
        cb.setGravity(Gravity.CENTER);
        cb.setBackgroundResource(R.drawable.red_white_selecter);
        cb.setTag(tag);
        cb.setText(Html.fromHtml(text));
//        cb.setText(StringUtils.matcherSearchText(color, text, keyword));
        cb.setChecked(isCheck);
        cb.setEnabled(isNotSale);
/*       if(type.equals(JCZQSHOWTYPE.SHOWDG) && (tag.contains("rqspf") || tag.contains("spf"))) {
            cb.setText("未开售");
            cb.setEnabled(false);
            cb.setTextColor(ContextCompat.getColor(getContext(),R.color.b));
        }*/
//       if(type.equals(JCZQSHOWTYPE.SHOWDG) && (tag.contains("rqspf"))) {
//           //让胜平负是不支持单关的；所以这里我们是需要将其弄成未开售
//            cb.setText("未开售");
//            cb.setEnabled(false);
//            cb.setTextColor(ContextCompat.getColor(getContext(),R.color.b));
//        }
        return cb;
    }

    /**
     * 判断是否开售的一个逻辑
     *
     * @param valueStr
     * @return
     */
    public boolean isNotSale(String valueStr) {
        float isEmpty = -1;
        try {
            isEmpty = Float.parseFloat(valueStr);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        if ((isEmpty != -1 && isEmpty == 0) || TextUtils.isEmpty(valueStr)) {
            return true;
        }
        return false;
    }

    @OnClick(R.id.tv_sure)
    void sure() {
        dismiss();
        Map<String, Map<String, String>> map = new LinkedHashMap<>();
        Map<String, String> spfCd = getCheckData(llSpf);
        if (spfCd.size() > 0)
            map.put("0", spfCd);//0-1统一 0-spf 1-rqspf
        Map<String, String> rqspfCd = getCheckData(llRQSpf);
        if (rqspfCd.size() > 0)
            map.put("1", rqspfCd);//0-1统一 0-spf 1-rqspf
        Map<String, String> bfCd = getCheckData(llBf);
        if (bfCd.size() > 0)
            map.put("3", bfCd);
        Map<String, String> zjqCd = getCheckData(llZjq);
        if (zjqCd.size() > 0)
            map.put("2", zjqCd);
        Map<String, String> bqcCd = getCheckData(llBqc);
        if (bqcCd.size() > 0)
            map.put("4", bqcCd);
        Map<String, String> sfcCd = getCheckData(llSfc);
        if (sfcCd.size() > 0)
            map.put("5", sfcCd);
        if (listener != null)
            listener.sure(map);
    }

    private Map<String, String> getCheckData(ViewGroup v) {
        int count = v.getChildCount();
        Map<String, String> list = new HashMap<>();
        for (int i = 0; i < count; i++) {
            if (v.getChildAt(i) instanceof CheckBox) {
                CheckBox cb = (CheckBox) v.getChildAt(i);
                if (cb.isChecked()) {
                    list.put(cb.getTag().toString(), cb.getTag().toString());
                }
            }
        }
        return list;
    }

    @OnClick(R.id.tv_cancel)
    void close() {
        dismiss();
    }


    /**
     * 解析tag参数
     *
     * @param tag
     * @return
     */
    boolean isCheckThisView(String tag, String index) {
        if (this.map.get(index) != null) {
            return this.map.get(index).get(tag) != null;
        }
        return false;
    }

    private OnSclestListener listener;

    public void setListener(OnSclestListener listener) {
        this.listener = listener;
    }


    //支持单关的小蓝点
    boolean isSupportDanguan(String realtype) {
        int mid = -1;
        boolean itemDgBool;
        switch (realtype) {
            case "bqc":
                mid = 0;
                break;
            case "cbf":
                mid = 1;
                break;
            case "jqs":
                mid = 2;
                break;
            case "rqspf":
                mid = 3;
                break;
            case "spf":
                mid = 4;
                break;
        }
        int value = TextUtils.isEmpty(codes[19]) ? 0 : Integer.parseInt(codes[19]);
        itemDgBool = ((value & 1 << mid) == (1 << mid));    //这是什么意思？
        return itemDgBool;
    }
}
